'\" t
.\"     Title: modbus_new_tcp_pi
.\"    Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\"      Date: 10/06/2013
.\"    Manual: Libmodbus Manual
.\"    Source: libmodbus 3.0.4
.\"  Language: English
.\"
.TH "MODBUS_NEW_TCP_PI" "3" "10/06/2013" "libmodbus 3\&.0\&.4" "Libmodbus Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
modbus_new_tcp_pi \- create a libmodbus context for TCP Protocol Independent
.SH "SYNOPSIS"
.sp
\fBmodbus_t *modbus_new_tcp_pi(const char *\fR\fB\fInode\fR\fR\fB, const char *\fR\fB\fIservice\fR\fR\fB);\fR
.SH "DESCRIPTION"
.sp
The \fImodbus_new_tcp_pi()\fR function shall allocate and initialize a modbus_t structure to communicate with a Modbus TCP IPv4 or Ipv6 server\&.
.sp
The \fInode\fR argument specifies the host name or IP address of the host to connect to, eg\&. \fI192\&.168\&.0\&.5\fR , \fI::1\fR or \fIserver\&.com\fR\&.
.sp
The \fIservice\fR argument is the service name/port number to connect to\&. To use the default Modbus port use the string "502"\&. On many Unix systems, it\(cqs convenient to use a port number greater than or equal to 1024 because it\(cqs not necessary to have administrator privileges\&.
.SH "RETURN VALUE"
.sp
The \fImodbus_new_tcp_pi()\fR function shall return a pointer to a \fBmodbus_t\fR structure if successful\&. Otherwise it shall return NULL and set errno to one of the values defined below\&.
.SH "ERRORS"
.PP
\fBEINVAL\fR
.RS 4
The node string is empty or has been truncated\&. The service string is empty or has been truncated\&.
.RE
.SH "EXAMPLE"
.sp
.if n \{\
.RS 4
.\}
.nf
modbus_t *ctx;

ctx = modbus_new_tcp_pi("::1", "1502");
if (ctx == NULL) {
    fprintf(stderr, "Unable to allocate libmodbus context\en");
    return \-1;
}

if (modbus_connect(ctx) == \-1) {
    fprintf(stderr, "Connection failed: %s\en", modbus_strerror(errno));
    modbus_free(ctx);
    return \-1;
}
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.sp
\fBmodbus_new_tcp\fR(3) \fBmodbus_new_rtu\fR(3) \fBmodbus_free\fR(3)
.SH "AUTHORS"
.sp
The libmodbus documentation was written by St\('ephane Raimbault <\m[blue]\fBstephane\&.raimbault@gmail\&.com\fR\m[]\&\s-2\u[1]\d\s+2>
.SH "NOTES"
.IP " 1." 4
stephane.raimbault@gmail.com
.RS 4
\%mailto:stephane.raimbault@gmail.com
.RE
